package com.example.cookie02.conterller;

import com.example.cookie02.dao.imp.PersonDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.logging.Handler;

/**
 * @author ：lqs
 * @date ：Created in 2023/8/30 14:44
 * @description：
 * @modified By：
 * @version:
 */
@WebServlet("/update")
public class UpdateController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        PersonDaoImpl personDao = new PersonDaoImpl();
        String option = req.getParameter("option");
        String id = req.getParameter("id");
        if (option==null) {
            List<Map<String, Object>> mapList = personDao.queryOne(id);
            req.setAttribute("oneMap", mapList.get(0));
            req.getRequestDispatcher("/update.jsp").forward(req, resp);
        }else if (option!=null && option.equals("end")){
            Map<String, String[]> parameterMap = req.getParameterMap();
            personDao.update(parameterMap);
            req.getRequestDispatcher("/show").forward(req, resp);

        }
        }

    }


